package cms.Test;

import static org.junit.Assert.*;

import java.util.Date;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import cms.business.CMSBusiness;
import cms.hibernate.po.*;

public class TestCMSBusiness {
	CMSBusiness bus=new CMSBusiness();
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Test
	public void testGetArticleById() {
		fail("Not yet implemented");
	}

	@Test
	public void testSaveArticle() {
		Article a=new Article();
		a.setTitle("hello");
		a.setCategoryId(2);
		a.setPublishTime((new Date()).toString());
		a.setExcerpt("news");
		a.setContent("helloworld");
		
		assertTrue("save article failed!",bus.saveArticle(a));
	}

	@Test
	public void testDeleteArticle() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeleteArticleById() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeleteArticleBatch() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetAllArticle() {
		fail("Not yet implemented");
	}
	@Test
	public void testGetArticleListByAuthor() {
		List result=bus.getArticleList(2, 1,1);
		assertNotNull("result is null",result);
		if(result==null)
			System.out.println("no article found ");
		else
		{
			System.out.println("find"+result.size()+" articles");
			Article a=null;
			for(Object o:result)
			{
				a=(Article)o;
				System.out.println(a.getTitle());
			}
		}
	}
	@Test
	public void testGetArticleList() {
		List result=bus.getArticleList(2, 1);
		assertNotNull("result is null",result);
		if(result==null)
			System.out.println("no article found ");
		else
		{
			System.out.println("find"+result.size()+" articles");
			Article a=null;
			for(Object o:result)
			{
				a=(Article)o;
				System.out.println(a.getTitle());
			}
		}
	}
	@Test
	public void testGetCategoryById() {
		fail("Not yet implemented");
	}

	@Test
	public void testSaveCategory() {
		assertTrue("save category failed",bus.saveCategory(null,"qwer2",-1));
		
	}

	@Test
	public void testDeleteCategory() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeleteCategoryById() {
		Integer id=1;
		assertTrue("delete category by id failed!",bus.deleteCategoryById(id));
	}

	@Test
	public void testDeleteCategoryBatch() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetAllCategory() {
		fail("Not yet implemented");
	}
	
	@Test
	public void testGetRootCategoryList() {
		List list = this.bus.getCategoryList(-1);
		for(Object o : list) {
			Category c = (Category)o;
			System.out.println(c.getCategoryName());
		}
			
	}
	
	@Test
	public void testGetCategoryByName(){
		String categoryName="w";
		List result=bus.getCategoryByName(categoryName,1,1);
		if(result!=null)
			System.out.println(result.size());
		else
			System.out.println("no result");
	}
	public void testGetCategoryByNameWithoutPage(){
		String categoryName="w";
		List result=bus.getCategoryByName(categoryName);
		if(result!=null)
			System.out.println(result.size());
		else
			System.out.println("no result");
	}
}
